package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.LogradouroModel;

/**
 *
 * @author WELISSON
 */
public class LogradouroDAO extends GenericDAO{
    public List<LogradouroModel> findByArgument(String argumento, String pesquisa) throws SQLException{
        
        List<LogradouroModel> logradouros = new ArrayList<LogradouroModel>();
        
        
        String select = "SELECT * FROM logradouro WHERE "+argumento+" = ? ";
        
        PreparedStatement stmt = 
            getConn().prepareStatement(select);
        
        stmt.setString(1, pesquisa);
        ResultSet rs = stmt.executeQuery();
        
        while (rs.next()) {
            LogradouroModel logradouro = new LogradouroModel();
            logradouro.setCep(rs.getString("cep"));
            logradouro.setEndereco(rs.getString("endereco"));
            logradouro.setBairro(rs.getString("bairro"));
            logradouro.setCidade(rs.getString("cidade"));
            logradouro.setUf(rs.getString("uf"));
            logradouros.add(logradouro);
        }
 
        rs.close();
        stmt.close();
        
        return logradouros;
    }
    
    
    
    
}
